/*
 * GridView.java
 *
 * Created on 30 de Agosto de 2007, 21:12
 *
 */

package bd;

/**
 * @author Evolution Systems - Do the Evolution
 */
import java.sql.*;
import javax.swing.table.*;
import javax.swing.*;

public class GridView {
	public static JTable table;
        private DataSet ds;
        
	public class GridViewModel extends AbstractTableModel 
	{
		String[] headings = ds.headings;
                Object[][] data = ds.data;
                
		public int getRowCount(  ) 
		{ 
			return data.length; 
		}
	  
		public int getColumnCount(  ) { return data[0].length; }

		public Object getValueAt(int row, int column) 
		{
			return data[row][column];
		}

		public String getColumnName(int column) 
		{
			return headings[column];
		}

		public Class getColumnClass(int column) 
		{
			return data[0][column].getClass(  );
		}
	}
	
	public void fill(DataSet ds) throws SQLException
	{      
            this.ds = ds;
            TableModel model = new GridViewModel();
            table = new JTable(model);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	}	
}
